﻿Imports System.Collections.Generic
Imports System.Data
Imports System.Data.SqlClient


''' <summary>
''' Clase de la capa de acceso a datos DAL que implementa el patrón Table Data Gateway para el manejo de la entidad Password
''' </summary>
''' <remarks></remarks>
Public Class TDGPassword

    Private Shared m_Instance As TDGPassword = Nothing


    Public Function Insert(conn As SqlConnection, _
                           Usu_Legajo As Int16, _
                           Pwd_Numero As Int16, _
                           Pwd_Password As String, _
                           Pwd_Fecha As DateTime, _
                           Pwd_FechaCaducacion As DateTime, _
                           DVH As Int32) As Int16
        Dim command As New SqlCommand
        Dim iRowsAffected As Int16


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.addPassword"
        command.Parameters.AddWithValue("@Usu_Legajo", Usu_Legajo)
        command.Parameters.AddWithValue("@Pwd_Password", Pwd_Password)

        iRowsAffected = command.ExecuteNonQuery()

        Return iRowsAffected

    End Function

    Public Function Find_PorUsuario(conn As SqlConnection, Usu_Legajo As Int16) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getPassword_PorUsuario_All"
        command.Parameters.AddWithValue("@Usu_Legajo", Usu_Legajo)

        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Function Find_PorUsuario_Ultimo(conn As SqlConnection, Usu_Legajo As Int16) As SqlDataReader
        Dim command As New SqlCommand
        Dim dr As SqlDataReader


        command.Connection = conn
        command.CommandType = CommandType.StoredProcedure

        command.CommandText = "dbo.getPassword_PorUsuario_Ultimo"
        command.Parameters.AddWithValue("@Usu_Legajo", Usu_Legajo)

        dr = command.ExecuteReader()

        Return dr

    End Function

    Public Shared ReadOnly Property Instance()
        Get
            If (m_Instance Is Nothing) Then
                m_Instance = New TDGPassword()
            End If

            Return m_Instance
        End Get
    End Property

    Private Sub New()
    End Sub

End Class
